include ../config.mk

dist_srcdir = AppKit
dist_FILES = \
	AppKit-gnustep.conf \
	AppKit-macos.conf \
	Makefile.in \
	$(NULL)

all: libHSAppKit.a HSAppKit.o

ghcmake: ghcmake.build-stamp

ghcmake.build-stamp:
	ln -sf ../Bindings/ifgen-output/Cocoa.hs .
	ln -sf ../Bindings/ifgen-output/AppKit.hs .
	ln -sf ../Bindings/ifgen-output/AppKit .
	test ! -d ../Bindings/ifgen-output/GNUstepGUI || \
		ln -sf ../Bindings/ifgen-output/GNUstepGUI .
	test ! -r ../Bindings/ifgen-output/GNUstepGUI.hs || \
		ln -sf ../Bindings/ifgen-output/GNUstepGUI.hs .
	mkdir -p build/objects
	mkdir -p build/imports
	$(GHC) --make AppKit.hs	\
		-package-name AppKit	\
		-odir build/objects \
		-hidir build/imports	\
		-package-conf ../HOC/HOC-$(PLATFORM).conf-inplace \
		-package-conf ../Foundation/Foundation.conf-inplace \
		-fglasgow-exts
	test ! -r GNUstepGUI.hs || \
		$(GHC) --make GNUstepGUI.hs	\
			-package-name AppKit	\
			-odir build/objects \
			-hidir build/imports	\
			-package-conf ../HOC/HOC-$(PLATFORM).conf-inplace \
			-package-conf ../Foundation/Foundation.conf-inplace \
			-fglasgow-exts
	$(GHC) -c Cocoa.hs \
		-package-name AppKit	\
		-ibuild/imports	   \
		-o build/objects/Cocoa.o	\
		-ohi build/imports/Cocoa.hi \
		-package-conf ../HOC/HOC-$(PLATFORM).conf-inplace \
		-package-conf ../Foundation/Foundation.conf-inplace \
		-fglasgow-exts
	touch $@
	
HSAppKit.o: ghcmake.build-stamp
	find build/objects/ -name \*.o | xargs ld -r -x -o HSAppKit.o

#libHSAppKit.a: ghcmake
#	find build/objects/ -name \*.o | xargs libtool -static -o libHSAppKit.a

libHSAppKit.a: HSAppKit.o
	rm -f libHSAppKit.a
	ar cq libHSAppKit.a HSAppKit.o
	ranlib libHSAppKit.a

clean:
	rm -rf build libHSAppKit.a HSAppKit.o AppKit.hs AppKit \
	    Cocoa.hs ghcmake.build-stamp

install: all
	mkdir -p $(GHC_LIB_PATH)/AppKit
	cp -R libHSAppKit.a HSAppKit.o build/imports \
		$(GHC_LIB_PATH)/AppKit/
	ranlib $(GHC_LIB_PATH)/AppKit/libHSAppKit.a
	ghc-pkg --update-package	\
			--input-file=AppKit-$(PLATFORM).conf

